import Taro from '@tarojs/taro'
import { getUserInfo, getConfigs, getCoupons } from './service';

export default {

  namespace: 'mine',

  state: {},

  effects: {
    * init(action, { call,put }) {
      const userInfo = yield call(getUserInfo);
      console.log('mine effects userInfo', userInfo);
      const servicePhone = yield call(getConfigs,'CustomerServicePhone');
      console.log('mine effects servicePhone', servicePhone);
      const coupons = yield call(getCoupons,'useable',userInfo.user.id);
      console.log('mine effects coupons', coupons);
      yield put({
        type:'save',
        payload: {
          servicePhone,
          coupons:coupons.list,
          userInfo
        }
      });
    },

  },

  reducers: {
    save(state, { payload }) {
      console.log('home effects payload',payload);
      return {
        ...state,
        ...payload
      };
    },
  },
};
